import 'dart:ui';
import 'package:flutter/material.dart';

part 'simple_alert.dart';

showAlert(
  BuildContext context, {
  ContentType contentType = ContentType.SIMPLE,
  ActionType actionType = ActionType.SIMPLE,
  ConfirmType confirmType = ConfirmType.SIMPLE,
  String? title,
  String? content,
  ContentBuilder? builder,
  Color confirmTextColor = const Color(0xff333333),
  Color cancelTextColor = const Color(0xff999999),
  String confirmTitle = '确定',
  String cancelTitle = '取消',
  OnCancel? onCancel,
  OnConfirm? onConfirm,
  bool needScroll = false,
  bool inWindowCenter: false,
  bool canPop = true,
}) {
 return  Navigator.of(context).push(
    _AlertRoute(
      child: _IAlert(
        content: content,
        contentType: contentType,
        actionType: actionType,
        confirmType: confirmType,
        title: title,
        confirmTextColor: confirmTextColor,
        cancelTextColor: cancelTextColor,
        builder: builder,
        confirmTitle: confirmTitle,
        cancelTitle: cancelTitle,
        onCancel: onCancel,
        onConfirm: onConfirm,
        inWindowCenter: inWindowCenter,
        needScroll: needScroll,
        canPop: canPop,
      ),
    ),
  ).then((value) => value);
}

enum ContentType { SIMPLE, NO_TITLE, CUSTOM }

enum ActionType {
  SIMPLE,
  SINGLE,
  NONE,
}

enum ConfirmType {
  SIMPLE,

  ///确认按钮校验，true 处理成功，弹窗消失  false 处理失败，弹窗保持
  VERIFY,
}

typedef Future<bool> OnConfirm();
typedef OnCancel();

typedef Widget ContentBuilder(BuildContext context);

double scale = MediaQueryData.fromWindow(window).size.width / 375.0;

extension RPX on num {
  double get rpx {
    return this * scale;
  }
}
